package edu.whu.rose.clock.ssql.binding;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import edu.whu.rose.clock.ssql.util.SequentialIntArray;

public class SequentialIntArrayBinding extends TupleBinding {

	public Object entryToObject(TupleInput input) {
		int[] result = new int[input.readInt()];
		for (int i = 0; i < result.length; i++) {
			result[i] = input.readInt();
		}
		return result;
	}
	
	public void objectToEntry(Object object, TupleOutput output) {
		SequentialIntArray sia = (SequentialIntArray)object;
		output.writeInt(sia.getCapacity());
		for (int i = 0; i < sia.getCapacity(); i++) {
			output.writeInt(sia.get(i));
		}
	}

}
